package com.hontech.bv.ui.fragment.pick

import android.view.View
import com.hontech.bv.R
import com.hontech.bv.model.pick.PickStatus
import com.hontech.bv.ui.view.NumberSensorView
import com.hontech.bv.ui.view.SwitchSensorView

class StatusDelegate (view: View) {

    private val sw1Guard = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_1_guard)
    private val sw2Guard = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_2_guard)

    private val sw1Open = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_1_open)
    private val sw1Close = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_1_close)

    private val sw2Open = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_2_open)
    private val sw2Close = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_2_close)

    private val sw1Check = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_1_check)
    private val sw2Check = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_2_check)

    private val numAdc = view.findViewById<NumberSensorView>(R.id.id_pick_adc)

    private val swStraw = view.findViewById<SwitchSensorView>(R.id.id_pick_sw_straw_close)

    fun update() {
        val status = PickStatus.status
        val sw = status.getSwitchValue()

        sw1Guard.set(sw.isLeftGuard)
        sw2Guard.set(sw.isRightGuard)

        sw1Open.set(sw.isLeftOpen)
        sw1Close.set(sw.isLeftClose)

        sw2Open.set(sw.isRightOpen)
        sw2Close.set(sw.isRightClose)

        sw1Check.set(sw.isLeftCheck)
        sw2Check.set(sw.isRightCheck)

        numAdc.set(status.adcValue.value)

        swStraw.set(sw.isStrawClose)
    }
}

